import { _decorator, Camera, Component, EventTouch, Node, UITransform, Vec3 } from 'cc';
import { CAgent } from './CAgent';
const { ccclass, property } = _decorator;

@ccclass('SBInput')
export class SBInput extends Component {
    @property(Camera)
    camera : Camera = null!
    @property(Node)
    point : Node = null!

    start() {
        this.node.on(Node.EventType.TOUCH_START, this.onTouchStart, this)
    }

    update(deltaTime: number) {
        
    }

    onTouchStart(et: EventTouch) {
        let tmpV2 = et.getLocation()
        let tpos = new Vec3(tmpV2.x, tmpV2.y, 0)
        let tmpV3 = this.camera.screenToWorld(tpos)
        tpos = this.node.getComponent(UITransform).convertToNodeSpaceAR(tmpV3)
        console.log(tpos);
        this.point.position = tpos
    }
}


